<template>
  <div>
    <a-input placeholder="请选择业务分类" @click="selectIds" v-model="selectedObj.categoryName" :disabled="disabled" readOnly></a-input>
    <business-category-select-modal ref="inputModal" @choseObj="choseObj"></business-category-select-modal>
  </div>
</template>

<script>
import { getAction } from '@/api/manage'
import BusinessCategorySelectModal from '@views/erp/components/modules/BusinessCategorySelectModal';

export default {
  name: 'BusinessCategorySelect',
  components: { BusinessCategorySelectModal },
  props: {
    disabled: {
      type: Boolean,
      required: false,
      default: false
    },
    value: {
      type: String,
      required: false,
      default: ''
    },
    urlList: {
      type: String,
      default: '/api/erp/files/employee/erpEmployeeFile/list2?auditStatus=2',
      required: false
    },
    props: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      categoryCode: null,
      selectedObj: {},
      list: [],
      objs: '',
      url: {
        list: '/api/erp/files/category/filesBusinessCategory/list',
      }
    }
  },
  mounted() {
    this.initObj(this.value);
  },
  watch: {
    value(val) {
      this.initObj(val);
    },
  },
  model: {
    prop: 'value',
    event: 'change'
  },
  methods: {
    initObj(categoryCode) {
      console.log(categoryCode);
      this.selectedObj = {};
      if (categoryCode) {
        let param = {};
        let url = this.url.list;
        param = { categoryCode: categoryCode };
        getAction(url, param).then((res) => {
          if (res.success) {
            if (res.result && res.result.records) {
              this.selectedObj = res.result.records[0];
              
              console.log('----this.selectedObj', this.selectedObj)
              this.selectedObj.categoryName = this.selectedObj.parentId_dictText ? (this.selectedObj.parentId_dictText + '/' + this.selectedObj.categoryName) : this.selectedObj.categoryName
            }
            this.$refs.inputModal.edit(res.result, this.categoryCode);
          }
        });
      } else {
        this.categoryCode = null;
        this.$refs.inputModal.edit(null, null);
      }

    },
    resetObj() {
      this.categoryCode = null;
      this.selectedObj = {};
      this.deleteCategoryCode = [];
      this.$refs.inputModal.edit(null, null);
    },
    selectIds() {
      if (!this.disabled) {
        // this.deleteId();
        this.$refs.inputModal.add(this.selectedObj, this.categoryCode);
      }
    },
    deleteId() {
      this.selectedObj = {}
    },
    // 子modal回调
    choseObj: function (obj) {
      //debugger;
      console.log('----2423234234-----')
      this.selectedObj = obj;
      this.categoryCode = obj.categoryCode;
      this.objs = obj.categoryCode;
      this.$emit('change', this.objs);
      this.$emit('back', this.selectedObj);
    },
  }
}
</script>

<style scoped>

</style>